package com.example.demo.service;

import com.example.demo.mapper.UserMapper;
import com.example.demo.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 马拉圈
 * Date: 2023-08-26
 * Time: 22:10
 */
@Service
public class TestService {

    @Autowired
    private UserMapper userMapper;

    public List<UserInfo> getAll() {
        return userMapper.getAll();
    }


    @Transactional(propagation = Propagation.NESTED)
    public int add(UserInfo userInfo) {
        int ret = userMapper.add2(userInfo);
        return ret;
    }

    @Transactional(propagation = Propagation.NESTED)
    public int insert(UserInfo userInfo) {
        int ret = userMapper.add2(userInfo);
        try {
            int num = 1 / 0;
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return ret;
    }


}


